<style lang="scss" scoped>
@import '../../css/training.scss';

@import '../../css/exam2.scss';

    .active{color: $mco;border-bottom:3px solid #3F66F6;}
    .show-exam-title{width: 70%;}
    .save-icon{width: 40px; height: 40px; float: right; cursor: pointer; background: #f7f8fa url('http://jhsy-img.caizhu.com/sass/images/save-ic.png') no-repeat center center;}
    .grey-check{ background-color: #edf2fc; border-color: #d8dce5; cursor: not-allowed;}
    .grey-txt{color: #b4bccc;cursor: not-allowed}
    .btn-plus{width: 38px;height: 38px;background: #fff;color: #8f95b3;text-align: center;line-height: 38px;border:1px  solid #e1e7eb;display: inline-block;cursor: pointer;vertical-align: middle;}
    .pass-score{width: 200px;}
    .total-txt{color:red;margin: 0px 5px;}
    .word-dialog-tap{padding: 8px 0 0 40px;}
    .input-dialog{padding-left: 40px;}
    .hide{display: none;}
</style>

<style>
    .apply-box .el-button--small{padding:0px;}
    .exam-bank-input-box .el-input{width: 316px;}
    .exam-topic-input-box .el-input{width: 316px;}
    .table-box .el-table th,.table-box .el-table td{text-align: center;}
</style>

<template>
    <section>

        <section class="breadcrumb-box clearfix">
            <el-breadcrumb separator=" > " class="fl">
                <el-breadcrumb-item >培训</el-breadcrumb-item>
                <el-breadcrumb-item :to="{path: '/training/training-manage'}">培训管理</el-breadcrumb-item>
                <el-breadcrumb-item v-if="$route.meta">{{$route.meta.title}}</el-breadcrumb-item>
            </el-breadcrumb>
        </section>

        <section class="exam-box">

            <section class="train-name pt30">《{{TrainName}}》考试</section>

            <section class="traniing-info-tab exam-info-tab p-relative">
                <span v-for="item,$index in tabList" :class="{'active': tabIndex ==$index}" @click="tabActive($index)">{{item}}</span>
                <div class="p-absolute exam-info-tabr" :class="step>0?'':'hide'">
                    <span class="mr20" @click="toPreview">预览</span>
                    <template v-if="step!= 0">
                        <template v-if="!existExamID">
                            <span class="ml from-bank" @click="questionListFlag = true">+  从题库选题</span>
                        </template>
                    </template>
                </div>
            </section>

            <!-- 没有试卷 -->
            <section v-if="step==0" class="exam-space">
                <span class="exam-space-item space-iconf" @click="step=1">
                    <img src="http://jhsy-img.caizhu.com/sass/images/Training-ic-paper.png" alt="">
                    <span class="space-txt fs-14 mt">新建空白试卷</span>
                </span>
                <div class="exam-space-item" @click="libListFlag = true">
                    <img src="http://jhsy-img.caizhu.com/sass/images/Training-ic-Test-paper.png" alt="">
                    <span class="space-txt fs-14 mt">试卷库中选择</span>
                </div>
            </section>

            <section v-else-if="step==1">
                <el-form ref="exam-form" :model="form" :rules="rules" class="mt30">

                    <!-- 显示 -->
                    <div :class="{hide:mainEditFlag}">
                        <div class="exam-line mt20">
                            <span>考试名称：{{form.ExamTitle}}</span>
                            <span class="exam-medit" @click="mainEditFlag=true"></span>
                        </div>
                        <div class="exam-line">
                            考试描述：{{form.ExamDesc}}
                        </div>
                        <div class="exam-line">
                            合格分数：{{form.PassScore}}
                        </div>
                        <div class="exam-line">
                            考试时长：{{form.AllowCostTime}}
                        </div>
                        <!-- <div class="exam-line">
                            知识体系：<span>{{form.CateName}}</span>
                        </div> -->
                    </div>

                    <div :class="{hide: !mainEditFlag}">
                        <el-form-item label="考试名称" prop="ExamTitle">
                            <el-input v-model="form.ExamTitle" placeholder="请输入考卷名称"></el-input>
                            <template v-if="existExamID">
                                <span class="save-icon" @click="doSaveAllTitle"></span>
                            </template>
                        </el-form-item>
                        <el-form-item label="考试描述" prop="ExamDesc">
                            <el-input v-model="form.ExamDesc" placeholder="请输入考卷描述"></el-input>
                        </el-form-item>

                        <el-form-item label="合格分数" prop="PassScore" class="">
                            <el-input type="number" v-model.number="form.PassScore"  placeholder="请输入合格分数"></el-input>
                        </el-form-item>
                        <el-form-item label="考试时长" prop="AllowCostTime">
                            <el-input v-model.number="form.AllowCostTime"  placeholder="请输入考试时长"></el-input>
                        </el-form-item>

                        <!--<div :class="{hide:!addFlag}">-->
                            <el-form-item label="知识体系" prop="InfoCateID">
                                <el-select v-model="form.InfoCateID" placeholder="请选择知识体系" @change="changeInfoCate">
                                    <el-option :label="one.CateName" :value="one.InfoCateID" v-for="one in InfoCateList" :key="one"></el-option>

                                </el-select>
                                <span class="btn-plus ml" @click="showAddTopicEdit = true">+</span>
                            </el-form-item>
                        <!--</div>-->

                    </div>

                    <div class="form-sepa mt20">

                        <!--初始化-->
                        <div class="exam-addbox mt20">
                            <span class="exama-one exama-i0" @click="addOne(2)">单选题</span>
                            <span class="exama-one exama-i1" @click="addOne(1)">多选题</span>
                            <span class="exama-one exama-i2" @click="addOne(3)">问答题</span>
                        </div>

                        <template v-for="outer,index in form.Questions">
                            <!-- 单选题+多选题 -->
                            <section :class="{hide:outer.editFlag}">  <!-- 显示 -->
                                <div class="exam-one clearfix mt20" v-if="outer.QuestionType!=3">
                                    <div class="examo-lef">
                                        <div class="">Q{{index+1}}</div>
                                        <div class="examo-do examo-edit mt" @click="editOne(index)"></div>
                                        <template v-if="!existExamID">
                                            <div class="examo-do examo-del" @click="delOne(index,outer.QuestionType)"></div>
                                        </template>
                                        <template v-if="existExamID">
                                            <template v-if="form.Questions.length > 1">
                                                <div class="examo-do examo-del" @click="delEditOne(index,outer)"></div>
                                            </template>

                                        </template>
                                    </div>
                                    <div class="examo-rig">
                                        <!-- 标题 -->
                                        <div class="examo-tit examo-line clearfix">
                                            <div class="examo-f01 show-exam-title">
                                                <span v-if="outer.QuestionType==1">【多选题】</span>
                                                <span v-else>【单选题】</span>

                                                <span class="">{{outer.QuestionTitle}}</span>
                                            </div>
                                            <div class="examo-f02">
                                                <span>{{outer.RightScore}}</span>
                                                <span>分</span>
                                            </div>
                                        </div>
                                        <!-- 选项 -->
                                        <div class="examo-one examo-line mt20 clearfix" v-for="one,iIndex in outer.Answers">
                                            <div class="examo-f00">
                                                <el-radio v-model.number="outer.RightAnswerIndexs" :label="iIndex" v-if="outer.QuestionType==2" disabled="true">{{answerArr[iIndex]}}</el-radio>
                                                <label v-else disabeld>
                                                    <span class="exam-checkbox grey-check" :class="judgeCheckOn(iIndex, outer.RightAnswerIndexs)?'checked':''"></span>
                                                    <span class="grey-txt">{{answerArr[iIndex]}}</span>
                                                </label>
                                                <span>{{one.AnswerValue}}</span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <!-- 问答题 -->
                                <div class="exam-one clearfix mt20" v-else>
                                    <div class="examo-lef">
                                        <div class="">Q{{index+1}}</div>
                                        <div class="examo-do examo-edit mt" @click="editOne(index)"></div>
                                        <template v-if="!existExamID">
                                            <div class="examo-do examo-del" @click="delOne(index,outer.QuestionType)"></div>
                                        </template>
                                        <template v-if="existExamID">
                                            <template v-if="form.Questions.length > 1">
                                                <div class="examo-do examo-del" @click="delEditOne(index,outer)"></div>
                                            </template>
                                        </template>

                                    </div>
                                    <div class="examo-rig">

                                        <div class="examo-one examo-line clearfix">
                                            <div class="examo-f00">
                                                <span>【问答题】</span>
                                                {{outer.QuestionTitle}}
                                            </div>
                                        </div>
                                        <div class="mt20">
                                            <span v-if="outer.Answers.length == 0">
                                            </span>
                                        </div>
                                    </div>
                                </div>

                            </section>

                            <section :class="{hide:!outer.editFlag}">
                                <div class="exam-one clearfix mt20" v-if="outer.QuestionType!=3">
                                    <div class="examo-lef">
                                        <div class="">Q{{index+1}}</div>
                                        <template v-if="!existExamID">
                                            <div class="examo-do examo-del mt20" @click="delEdit(index,outer.QuestionType)"></div>
                                        </template>
                                        <template v-if="existExamID">
                                            <template v-if="form.Questions.length > 1">
                                                <template v-if="editOldTopic">
                                                    <template v-if="!createNewTopic">
                                                        <div class="examo-do examo-del" @click="delEditTwo(index,outer)"></div>
                                                    </template>
                                                </template>
                                                <template v-if="!editOldTopic">
                                                    <template v-if="createNewTopic">
                                                        <div class="examo-do examo-del" @click="delEditThree(index,outer)"></div>
                                                    </template>
                                                </template>
                                            </template>

                                        </template>
                                    </div>
                                    <div class="examo-rig">
                                        <!-- 标题 -->
                                        <div class="examo-tit clearfix">
                                            <div class="examo-f00">
                                                <el-input class="examo-inp00" placeholder="标题" v-model="outer.QuestionTitle"></el-input>
                                            </div>
                                            <div class="examo-f01">
                                                <span v-if="outer.QuestionType==1">【多选题】</span>
                                                <span v-else>【单选题】</span>
                                            </div>
                                            <div class="examo-f02">
                                                <span>分值</span>
                                                <el-input class="examo-inp01" v-model="outer.RightScore"></el-input>
                                                <span>分</span>
                                            </div>
                                        </div>
                                        <!-- 选项 -->
                                        <div class="examo-one mt20 clearfix" v-for="one,iIndex in outer.Answers">
                                            <div class="examo-f00">
                                                <el-radio v-model="outer.RightAnswerIndexs" :label="iIndex" v-if="outer.QuestionType==2">{{answerArr[iIndex]}}</el-radio>
                                                <label @click="checkAnswerOne(iIndex, outer.RightAnswerIndexs, index, 3)" v-else>
                                                    <span class="exam-checkbox" :class="judgeCheckOn(iIndex, outer.RightAnswerIndexs)?'checked':''"></span>
                                                    <span>{{answerArr[iIndex]}}</span>
                                                </label>
                                                <el-input class="examo-inp02 ml" placeholder="标题" v-model="one.AnswerValue"></el-input>

                                            </div>
                                            <div class="examo-f01">

                                                <el-radio v-model="outer.RightAnswerIndexs" :label="iIndex" v-if="outer.QuestionType==2">设为答案</el-radio>
                                                <label @click="checkAnswerOne(iIndex, outer.RightAnswerIndexs, index, 3)" v-else>
                                                    <span class="exam-checkbox" :class="judgeCheckOn(iIndex, outer.RightAnswerIndexs)?'checked':''"></span>
                                                    <span>设为答案</span>
                                                </label>
                                            </div>
                                            <div class="examo-f02">
                                                <span class="examo-do examo-tot" :class="{'hide':firstIndex == iIndex}" @click="switchUp(one,iIndex,outer.Answers,outer)"></span>
                                                <span class="examo-do examo-tob" :class="{'hide': outer.Answers.length-1 == iIndex}"  @click="switchDown(one,iIndex,outer.Answers,outer)"></span>
                                                <span class="examo-do examo-del" @click="delAnswerOne(index,iIndex)"></span>
                                            </div>
                                        </div>
                                        <!-- 添加按钮 -->
                                        <div class="examo-add mt20" @click="addAnswerOne(index)">+添加选项</div>

                                        <template v-if="!existExamID">
                                            <div class="examo-save mt20" @click="saveAnswerOne(index, outer.QuestionType)" v-if="outer.editFlag">保存</div>
                                            <div class="examo-cancel mt20 ml" @click="cancelAnswerOne(index)" v-if="cancelOneFlag">取消</div>
                                        </template>
                                        <template v-if="existExamID">
                                            <template v-if="!editOldTopic">
                                                <template v-if="createNewTopic">
                                                    <div class="examo-save mt20" @click="saveEditNewAnswerOne(outer,index, outer.QuestionType)" v-if="outer.editFlag">保存</div>
                                                    <div class="examo-cancel mt20 ml" @click="cancelEditNewAnswerOne(index)" v-if="cancelOneFlag">取消</div>
                                                </template>
                                            </template>

                                            <template v-if="editOldTopic">
                                                <template v-if="!createNewTopic">
                                                    <div class="examo-save mt20" @click="saveEditOldAnswerOne(outer,index, outer.QuestionType)" v-if="outer.editFlag">保存</div>
                                                    <div class="examo-cancel mt20 ml" @click="holdOldOne(index)" v-if="cancelOneFlag">取消</div>
                                                </template>
                                            </template>
                                        </template>

                                    </div>
                                </div>
                                <!-- 问答题 -->
                                <div class="exam-one clearfix mt20" v-else>
                                    <div class="examo-lef">
                                        <div class="">Q{{index+1}}</div>
                                        <template v-if="!existExamID">
                                            <div class="examo-do examo-del mt20" @click="delEdit(index,outer.QuestionType)"></div>
                                        </template>
                                        <template v-if="existExamID">
                                            <template v-if="form.Questions.length > 1">
                                                <template v-if="editOldTopic">
                                                    <template v-if="!createNewTopic">
                                                        <div class="examo-do examo-del" @click="delEditTwo(index,outer)"></div>
                                                    </template>
                                                </template>
                                                <template v-if="!editOldTopic">
                                                    <template v-if="createNewTopic">
                                                        <div class="examo-do examo-del" @click="delEditThree(index,outer)"></div>
                                                    </template>
                                                </template>
                                            </template>

                                        </template>
                                    </div>
                                    <div class="examo-rig">

                                        <div class="examo-one clearfix">
                                            <div class="examo-f00">
                                                <el-input class="examo-inp00" placeholder="标题" v-model="outer.QuestionTitle"></el-input>
                                            </div>
                                            <div class="examo-f01">
                                                <span>【问答题】</span>
                                            </div>
                                        </div>
                                        <template v-if="!existExamID">
                                            <div class="examo-save mt20" @click="saveAnswerOne(index, outer.QuestionType)" v-if="outer.editFlag">保存</div>
                                            <div class="examo-cancel mt20 ml" @click="cancelAnswerOne(index)" v-if="cancelOneFlag">取消</div>
                                        </template>
                                        <template v-if="existExamID">
                                            <template v-if="!editOldTopic">
                                                <template v-if="createNewTopic">
                                                    <div class="examo-save mt20" @click="saveEditNewAnswerOne(outer,index, outer.QuestionType)" v-if="outer.editFlag">保存</div>
                                                    <div class="examo-cancel mt20 ml" @click="cancelEditNewAnswerOne(index)" v-if="cancelOneFlag">取消</div>
                                                </template>
                                            </template>
                                            <template v-if="editOldTopic">
                                                <template v-if="!createNewTopic">
                                                    <div class="examo-save mt20" @click="saveEditOldAnswerOne(outer,index, outer.QuestionType)" v-if="outer.editFlag">保存</div>
                                                    <div class="examo-cancel mt20 ml" @click="holdOldOne(index)" v-if="cancelOneFlag">取消</div>
                                                </template>
                                            </template>
                                        </template>
                                    </div>
                                </div>
                            </section>

                        </template>


                        <!--添加选择题-->
                        <div class="exam-addbox mt20" :class="{hide:!form.Questions.length}">
                            <span class="exama-add mr"></span>
                            <template v-if="addBtnFlag">
                                <span class="exama-one exama-tip" @mouseover="addOver">添加题目</span>
                            </template>
                            <template v-else>
                                <div class="exama-dos" @mouseout="outAddBtn" @mousemove="moveAddBtn">
                                    <span class="exama-one exama-i0" @click="addOne(2,true)">单选题</span>
                                    <span class="exama-one exama-i1" @click="addOne(1,true)">多选题</span>
                                    <span class="exama-one exama-i2" @click="addOne(3,true)">问答题</span>
                                </div>
                            </template>
                        </div>

                    </div>

                    <template v-if="!existExamID">


                        <section class="mt">
                            <p class="pt20 pb20">试卷详情</p>
                            <table class="exam-detail-table fs-14">
                                <thead>
                                <tr class="">
                                    <th>题型</th>
                                    <th>单选题</th>
                                    <th>多选题</th>
                                    <th>问答题</th>
                                </tr>
                                </thead>
                                <tbody>

                                <tr>
                                    <th>题数</th>
                                    <td>{{showForm.SingleChoiceNum}}道</td>
                                    <td>{{showForm.MultiChoiceNum}}道</td>
                                    <td>{{showForm.AskAnswerNum}}道</td>
                                </tr>
                                <tr>
                                    <th>分值</th>
                                    <td>{{showForm.SingleChoiceScore}}分</td>
                                    <td>{{showForm.MultiChoiceScore}}分</td>
                                </tr>
                                <tr>
                                    <th>合计</th>
                                    <td colspan="2" ></td>
                                    <td>卷面总计{{showForm.TotalScore}}分</td>
                                </tr>
                                </tbody>
                            </table>
                        </section>

                        <div class="exama-minor mt20" :class="{hide:!addFlag}">
                            <el-checkbox v-model="form.isJoinExamLib" true-label="1" value="1">将试卷保存到试卷库</el-checkbox>
                            <el-checkbox v-model="form.isJoinQuestionLib" true-label="1" value="1">将试题保存到题目库</el-checkbox>
                        </div>
                        <div class="mt20">
                            <template v-if="!paperIsApply">
                                <template v-if="!submitFlag">
                                    <el-button type="primary" @click="submitForm('exam-form')">生成试卷</el-button>
                                </template>
                            </template>

                        </div>
                    </template>

                    <template v-if="existExamID">

                        <section class="mt">
                            <p class="pt20 pb20">试卷详情</p>
                            <table class="exam-detail-table fs-14">
                                <thead>
                                <tr class="">
                                    <th>题型</th>
                                    <th>单选题</th>
                                    <th>多选题</th>
                                    <th>问答题</th>
                                </tr>
                                </thead>
                                <tbody>

                                <tr>
                                    <th>题数</th>
                                    <td>{{form.SingleChoiceNum}}道</td>
                                    <td>{{form.MultiChoiceNum}}道</td>
                                    <td>{{form.AskAnswerNum}}道</td>
                                </tr>
                                <tr>
                                    <th>分值</th>
                                    <td>{{form.SingleChoiceScore}}分</td>
                                    <td>{{form.MultiChoiceScore}}分</td>
                                </tr>
                                <tr>
                                    <th>合计</th>
                                    <td colspan="2" ></td>
                                    <td>卷面总计 <span class="total-txt">{{form.TotalScore}}</span> 分</td>
                                </tr>
                                </tbody>
                            </table>
                        </section>

                    </template>

                </el-form>

            </section>

            <!-- 发放试卷 -->
            <section v-else-if="step==2">
            </section>

            <!-- 考试结果 -->
            <section v-else-if="step==3">

            </section>

        </section>


        <el-dialog
                title="添加知识体系"
                :visible.sync="showAddTopicEdit"
                width="30%"
                center
              >
            <el-input class="input-dialog" type="text" v-model="CateName"  placeholder="输入添加的知识体系名称" @input="cutLength"></el-input>
            <p class="word-dialog-tap"><span style="color:red;">*</span>小于等于8个字符</p>
            <span slot="footer" class="dialog-footer">
                <el-button :plain="true" @click="doAdd">增 加</el-button>
                <el-button type="primary" @click="cancelEditCateNme">取 消</el-button>
              </span>
        </el-dialog>


        <el-dialog
                title="试卷详情"
                :visible.sync="showPaperDetail"
                width="50%"
                center>
            <section class="detail-stu-info fs-14">
                <span class="mt20">姓名：smile</span>
                <span class="mt20">工号：219</span>
                <span class="mt20">公司：219</span>
                <span class="mt20">手机：15637882778</span>
            </section>
            <section class="detail-stu-score fs-14 mt20">
                <div class="p-relative detail-stu-title">
                    <span class="p-absolute exam-space-linet">考试结果</span>
                    <div class="exam-space-line"></div>
                </div>
                <p class="mt20"><span>得分：20分</span><span class="stu-test-status ml20">通过</span></p>
                <p class="mt20">排名：第1名</p>
            </section>
            <section class="mt30">
                <div class="p-relative detail-stu-title">
                    <span class="p-absolute exam-space-linet">问卷</span>
                    <div class="exam-space-line"></div>
                </div>
                <ul>
                    <li class="p-relative mt exam-question ">
                        <div class="question-content mt20">
                            <p class="question-topic">
                                <span>1</span>
                                <span>【单选题】</span>
                                <span>迟到几次不扣工资</span>
                            </p>
                            <ul class="question-options">
                                <el-radio-group v-model="questionRadio">
                                    <li class="mt20 fs-14">
                                        <el-radio label="1" disabled >A<span class="ml20"></span>1次</el-radio>
                                    </li>
                                    <li class="mt20 fs-14">
                                        <el-radio label="2" disabled >B<span class="ml20"></span> 1次</el-radio>
                                    </li>
                                    <li class="mt20 fs-14">
                                        <el-radio label="3" disabled >C<span class="ml20"></span>1次</el-radio>
                                    </li>
                                    <li class="mt20 fs-14">
                                        <el-radio label="4" >D<span class="ml20"></span>1次</el-radio>
                                    </li>
                                </el-radio-group>
                            </ul>
                            <div class="question-down clearfix mt20">
                                <span class="fs-14 question-down-left fl fs-14">学员回答∶B</span>
                                <span class="fr">
                                    <img src="http://jhsy-img.caizhu.com/sass/images/correct-icon.png" alt="">
                                    <span class="fs-14 question-down-right">（得10分）</span>
                                </span>
                            </div>
                        </div>
                        <div class="p-absolute answers-score">（10分）</div>
                    </li>
                    <li class="p-relative mt exam-question ">
                        <div class="question-content mt20">
                            <p class="question-topic">
                                <span>1</span>
                                <span>【单选题】</span>
                                <span>迟到几次不扣工资</span>
                            </p>
                            <ul class="question-options">
                                <el-radio-group v-model="questionRadio">
                                    <li class="mt20 fs-14">
                                        <el-radio label="1" disabled >A<span class="ml20"></span>1次</el-radio>
                                    </li>
                                    <li class="mt20 fs-14">
                                        <el-radio label="2" disabled >B<span class="ml20"></span> 1次</el-radio>
                                    </li>
                                    <li class="mt20 fs-14">
                                        <el-radio label="3" disabled >C<span class="ml20"></span>1次</el-radio>
                                    </li>
                                    <li class="mt20 fs-14">
                                        <el-radio label="4" >D<span class="ml20"></span>1次</el-radio>
                                    </li>
                                </el-radio-group>
                            </ul>
                            <div class="question-down clearfix mt20">
                                <span class="fs-14 question-down-left fl fs-14">学员回答∶B</span>
                                <span class="fr">
                                    <img src="http://jhsy-img.caizhu.com/sass/images/correct-icon.png" alt="">
                                    <span class="fs-14 question-down-right">（得10分）</span>
                                </span>
                            </div>
                        </div>
                        <div class="p-absolute answers-score">（10分）</div>
                    </li>
                    <li class="p-relative mt exam-question ">
                        <div class="question-content mt20">
                            <p class="question-topic">
                                <span>1</span>
                                <span>【单选题】</span>
                                <span>迟到几次不扣工资</span>
                            </p>
                            <ul class="question-options">
                                <el-radio-group v-model="questionRadio">
                                    <li class="mt20 fs-14">
                                        <el-radio label="1" disabled >A<span class="ml20"></span>1次</el-radio>
                                    </li>
                                    <li class="mt20 fs-14">
                                        <el-radio label="2" disabled >B<span class="ml20"></span> 1次</el-radio>
                                    </li>
                                    <li class="mt20 fs-14">
                                        <el-radio label="3" disabled >C<span class="ml20"></span>1次</el-radio>
                                    </li>
                                    <li class="mt20 fs-14">
                                        <el-radio label="4" >D<span class="ml20"></span>1次</el-radio>
                                    </li>
                                </el-radio-group>
                            </ul>
                            <div class="question-down clearfix mt20">
                                <span class="fs-14 question-down-left fl fs-14">学员回答∶B</span>
                                <span class="fr">
                                    <img src="http://jhsy-img.caizhu.com/sass/images/correct-icon.png" alt="">
                                    <span class="fs-14 question-down-right">（得10分）</span>
                                </span>
                            </div>
                        </div>
                        <div class="p-absolute answers-score">（10分）</div>
                    </li>
                </ul>
            </section>


            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="showPaperDetail = false">知道了</el-button>
            </span>
        </el-dialog>


        <el-dialog
                title="题库选择"
                :visible.sync="questionListFlag"
                width="50%"
                center>
            <section class="signup-total exam-topic-input-box">
                <el-input placeholder="请输入题目内容" v-model="questionKeyword" class="input-with-select">
                    <el-button slot="append" icon="el-icon-search" @click="questionChange()"></el-button>
                </el-input>
            </section>
            <section class="table-box mt apply-box">
                <el-table :data="questionList" height="500" v-loading="questionLoading">
                    <el-table-column property="QuestionTitle" label="题目" style="text-align: center;"></el-table-column>
                    <el-table-column label="类型">
                        <template slot-scope="one">
                            {{one.row.QuestionType | filterType}}
                        </template>
                    </el-table-column>
                    <el-table-column property="CateName" label="知识体系"></el-table-column>
                    <el-table-column property="RightScore" label="题分"></el-table-column>
                    <el-table-column label="操作">
                        <template slot-scope="one">
                            <el-button type="text" size="small" @click="questionApply(one.row.QID,one.row)">应用</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </section>
            <section class="mt20 clearfix">
                <section class="fr">
                    <el-pagination
                            @size-change="getQuestionList"
                            @current-change="getQuestionList"
                            :page-size="pageQuestionInfo.pageSize"
                            layout="prev, pager, next, jumper"
                            :total="pageQuestionInfo.total">
                    </el-pagination>
                </section>
            </section>
        </el-dialog>


        <el-dialog title="试卷选择" :visible.sync="libListFlag" width="50%" center>
            <section class="signup-total exam-bank-input-box">
               <!-- <el-input
                        placeholder="请输入试卷名称"
                        prefix-icon="el-icon-search"
                        v-model="libKeyword"
                        debounce="200"
                        @change="libChange"
                        class="sign-input">
                </el-input>-->
                <el-input placeholder="请输入试卷名称" v-model="libKeyword" class="input-with-select">
                    <el-button slot="append" icon="el-icon-search" @click="libChange()"></el-button>
                </el-input>
            </section>
            <section class="table-box mt">
                <el-table :data="libList" height="500" v-loading="libLoading">
                    <el-table-column property="ExamTitle" label="试卷名称"></el-table-column>
                    <el-table-column property="QuestionNum" label="试卷题目数"></el-table-column>
                    <el-table-column property="CreateTime" label="创建时间"></el-table-column>
                    <el-table-column label="操作">
                        <template slot-scope="scope">
                            <el-button type="text" size="small" @click="libApply(scope.row.ExamLibID)">应用</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </section>
            <section class="mt20 clearfix">
                <section class="fr">
                    <el-pagination
                            @size-change="getLibList"
                            @current-change="getLibList"
                            :page-size="pageLibInfo.pageSize"
                            layout="prev, pager, next, jumper"
                            :total="pageLibInfo.total">
                    </el-pagination>
                </section>
            </section>
            <!--<span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="libListFlag = false">知道了</el-button>
            </span>-->
        </el-dialog>


        <el-dialog title="提示" :visible.sync="delOneFlag" width="30%" :before-close="handleClose">
            <span>这是一段信息</span>
              <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
              </span>
        </el-dialog>

    </section>
</template>

<script>

import qs from 'qs'
import com from 'js/common'
//import editor from '../../components/wangeditor.vue'
let answerArr = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'G', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
Vue.filter('filterType', n=>{
	var arr = ['', '多选题', '单选题', '问答题'];
	return arr[n];
});



export default{
    data: function(){
        return {
        	paperIsApply:false,  /*应用试卷*/
			showAddTopicEdit: false,  //增加知识体系
			CateName: '',


            questionLoading: false,
            questionKeyword: '',
            questionList: [],
            pageQuestionInfo: {
                pageSize: 20,
                total:0,
                page:1
            },

            libLoading: false,
            libKeyword: '',
            libList: [],
            pageLibInfo: {
                pageSize: 20,
                total:0,
                page:1
            },

            outTimeId: '',
            answerArr: answerArr,
            tabList:['编辑试卷','发放试卷','考试结果'],
            tabIndex: 0,

            step: 0,
            initHasTest: false,

            questionListFlag: false,      // 题库选题弹框
            libListFlag: false,      // 卷库中选择弹框

            mainEditFlag: true,      // 头部编辑状态 - eg：考试名称、分数
            addBtnFlag: true,      // 是否显示添加试题按钮
            editFlag: false,      // 是否编辑当中
            editTip: '请先完成试卷的编辑！',
            cancelOneFlag: false,      // 添加题目时取消添加


            form: {
                ExamID: '',
				ExamTitle:'',
				ExamDesc:'',
				PassScore:'',
				AllowCostTime:'',
				InfoCateID:'',
				CateName:'',
                Questions: [] ,     // oneEditFlag， 手动添加， 编辑状态

            },
            InfoCateList: [],      // 知识体系


            rules: {
                ExamTitle: [
                    { required: true, message: '请输入考试名称', trigger: 'blur' }
                ],
                ExamDesc: [
                    { required: true, message: '请输入考试描述', trigger: 'blur' }
                ],
                PassScore: [
                    { required: true, message: '请输入合格分数', trigger: 'blur' },
//                    { type: 'number', message: '合格分数为数字值',trigger: 'blur' }
                ],
                AllowCostTime: [
                    { required: true, message: '请输入考试时长', trigger: 'blur'},
                    { type: 'number', message: '考试时长为数字值'}
                ],
				InfoCateID: [
                    { required: true, message: '请选择知识体系', trigger: 'change' }
                ]
            },

            hasExamId: false,

            /*有试卷id*/
			editOldTopic: false, // 初始化默认未修改
			createNewTopic: false,/*初始化未创建*/

			existExamID: false, /*默认没有试卷*/
			ExamQIDs:[],

			showForm:{
				SingleChoiceNum: '0',
                MultiChoiceNum: '0',
				AskAnswerNum: '0',
				SingleChoiceScore: '0',
				MultiChoiceScore: '0',
				TotalScore: '0'
            }, /*新建试卷--展示题目数-不传*/

			submitFlag: false, /*预览是否可点*/
			TrainName:'', /*培训名称*/

			firstIndex: 0,
        }
    },
    computed: {
        hasExamId: function(){
			this.form.ExamID = this.$router.query.ExamID;
            if( this.form.ExamID > 0){
                return true;
            }
            return false;
        },
        addFlag: function(){      // 是添加还是编辑
            if(this.form.ExamLibID > 0){
                return false;
            }
            return true;
        }
    },
    mixins: [mixinMethods],
    methods: {
        cutLength(){     //控制添加知识体系时输入长度
            if(this.CateName.length>8){
                this.$message.error('最多输入8个字符');
                this.$nextTick(()=>{
                    this.CateName = this.CateName.substring(0,8);
                })
            }
        },
		doAdd(){
			axios.post('/com/info-cates/add', qs.stringify({
				CateName: this.CateName,
			})).then( (res) => {
				var d = res.data;
				if(d.flag == 1){
					this.showAddTopicEdit = false;
					this.$message.success('添加成功');

					this.getCateNameList(1);

					this.CateName = ''; // 清空内容

				}else{
					this.$message.error(d.msg);
				}
			} );
		},
		getCateNameList(addFlag){
			axios.post('/com/info-cates/list').then( (res)=>{
				var d = res.data;
				if(d.flag == 1){
					this.InfoCateList = d.data.InfoCateList;
					if(addFlag==1){
						this.form.CateName = this.InfoCateList[this.InfoCateList.length-1].CateName;
                        this.form.InfoCateID = this.InfoCateList[this.InfoCateList.length-1].InfoCateID;
                    }
				}else{
					this.$message.error(d.msg);
                }
			} );
        },

		cancelEditCateNme(){
			this.showAddTopicEdit = false;
			this.CateName = ''; // 清空内容
        },

    	toPreview(){
			let ExamID = this.$route.query.ExamID;
			if(ExamID > 0){
				location.assign('/training/exam-preview' +'?ExamID='+ ExamID)
			}else{
				localStorage.setItem("formInfo",JSON.stringify({
					"form":this.form,
				}));
				location.assign('/training/exam-preview');
			}

        },

        getTrainName(){
			let TrainID = this.$route.query.TrainID;// 培训id
			axios.post('/com/train/get', qs.stringify({
				trainID: TrainID
            })).then( (res) => {
             var d = res.data;
                 if(d.flag == 1){
                 	this.TrainName = d.data.TrainName;
                 }else{
                 	this.$message.error(d.msg);
                 }
             } )
        },

    	initPageEvent(){
            var ExamID = this.$route.query.ExamID;
			this.form.ExamID = ExamID;
			if(ExamID == undefined){
				localStorage.getItem("formInfo");
				let form = localStorage.getItem("formInfo");
				if(form){
					let form1 = JSON.parse(form);
					this.form =form1.form;
					this.step = 1;
				}else{
					this.step = 0;
					this.initHasTest = false;  // 无试卷
					this.existExamID = false;
                }

			}else if(ExamID == 0){

				localStorage.getItem("formInfo");
				let form = localStorage.getItem("formInfo");
				if(form){
					let form1 = JSON.parse(form);
					this.form =form1.form;
					this.step = 1;
				}else{
					this.step = 0;
					this.initHasTest = false;  // 无试卷
					this.existExamID = false;
				}
			}else if(ExamID > 0){
				this.initHasTest = true; // 有试卷
                this.existExamID = true; /*存在试卷*/
			    this.step = 2;
                this.mainEditFlag = false;  /*最外层编辑状态*/
				this.getOne(ExamID);
				this.submitFlag = true;
				return true;
			}else{
				return false;
			}
        },


        editMainInfo: function(){      // 编辑头部资料
            axios.post('/com/exam/edit', qs.stringify({
                examTitle: this.form.ExamTitle,
                examDesc: this.form.ExamDesc,
                passScore: this.form.PassScore,
                allowCostTime: this.form.AllowCostTime,
                examID: this.form.ExamID,
                examLibID: this.form.ExamLibID
            })).then( (res)=>{
                var d = res.data;
                if(d.flag == 1){
                    this.mainEditFlag = false;
                }
            } );
            return true;
        },
        tabActive: function(i){
            if(!this.initHasTest){
                this.$message.error(this.editTip);
                this.addBtnFlag = true;
                return ;
            }

            this.tabIndex = i;
            this.step = i+1;
			let TrainID = this.$route.query.TrainID;// 培训id
			if(this.step == 2){
				location.assign('/training/push-paper'+'?ExamID='+this.form.ExamID + '&TrainID=' + TrainID);
            }else if(this.step == 3){
				location.assign('/training/exam-result'+'?ExamID='+this.form.ExamID + '&TrainID=' + TrainID);
            }
        },

        questionApply: function(id,one){   // 试卷提题库题目应用
            if(this.editFlag){
                this.$message.error(this.editTip)
                return ;
            }

            /*
            this.questionListFlag = false;
            //one.editFlag = false;
            this.form.Questions.push(one);*/
			let arr = [];
			this.form.Questions.forEach((item)=>{
				arr.push(item.QID);
			});
			if(arr.indexOf(one.QID) > -1){
				this.$message.error('该试卷中已经存在该试题，请重新选择其它试题！');
			}else{
				this.getQuestionOne(id,one);
			}
        },
        libApply(id){   // 试卷库应用
            this.getLibOne(id);
        },

        getOne(id){
			axios.post('/com/exam/get', qs.stringify({
				examID: id
			})).then( (res)=>{
				var d = res.data;

				this.libListFlag = false;
				this.editFlag = false;

				if(d.flag == 1){
					d = d.data;
					d.AllowCostTime = +d.AllowCostTime;
					d.Questions.forEach(function(one){
						if(one.QuestionType==2){
							one.RightAnswerIndexs = +one.RightAnswerIndexs;
						}
					})

					d.Questions.forEach(function(one){
						one.editFlag = false;
					})


					//this.editFlag = true;
					this.form = d;
					this.form.ExamID = id;
					this.step = 1;
				}
			} );
        },

        questionChange: function(){
            this.getQuestionList();
        },
        libChange: function(){
            this.getLibList();
        },
        outAddBtn: function(){
            clearTimeout(this.outTimeId);
            this.outTimeId = setTimeout(()=>{
                this.addBtnFlag = true;
            }, 600);
        },
        moveAddBtn: function(){
            clearTimeout(this.outTimeId);
        },
        addOver: function(){
            this.addBtnFlag = false
        },
        addOne: function(n, type){
            let self= this;
            if(self.editFlag){
				self.$message.error(this.editTip)
                return ;
            }

            if(self.existExamID){
				self.editOldTopic = false;
				self.createNewTopic = true;
				self.cancelOneFlag = true;
				self.editFlag = true;
				if(type){
					self.editOldTopic = false;
					self.createNewTopic = true;
					self.cancelOneFlag = true;
					self.editFlag = true;
                }

				stepTwo();

            }else if(!self.existExamID){
				self.cancelOneFlag = true;
				self.editFlag = true;
				if(type){
					self.cancelOneFlag = true;
					self.addBtnFlag = true;
				}
				stepOne();
            }


            function stepOne(){
				var obj;
// RightAnswerIndexs
				if(n==1 || n==2){
					obj = {QuestionTitle: '', RightScore: '', RightAnswerIndexs: '',
						Answers: [
							{},
							{},
                            {},
                            {}
						]
					}
				}else{
					obj = {AnswerValue: '',
						Answers: [
							{},
							{}
						]
					}
				}
				stepThree(obj);
            }

            function stepTwo(){
				var obj;
// RightAnswerIndexs
				if(n==1 || n==2){
					obj = {QuestionTitle: '',  RightScore: '', RightAnswerIndexs: '',ExamQID: '0',
						Answers: [
							{},
							{},
                            {},
                            {}
						]
					}
				}else{
					obj = {AnswerValue: '',ExamQID: '0',
						Answers: [
							{},
							{}
						]
					}
				}
				stepThree(obj);
            }

            function stepThree(obj){
				if(n == 1){
					obj.QuestionType = 1;
					//obj.RightAnswerIndexs = [];
				}else if(n == 2){
					obj.QuestionType = 2;
					//obj.RightAnswerIndexs = '';
				}else if(n == 3){
					obj.QuestionType = 3;
				}

				obj.editFlag = true;      // 默认编辑状态

				self.form.Questions.push(obj);
            }
        },
		editOne : function(index){
            if(this.editFlag){
                this.$message(this.editTip);
                return ;
            }
            this.editFlag = true;
            if(this.existExamID){
				this.editOldTopic = true;
				this.cancelOneFlag = true;
            }
			this.form.Questions[index].editFlag = true;

        },

        delOne(index,type){
            if(this.editFlag){
                this.$message(this.editTip);
                return ;
            }

            this.$confirm('确认删除？').then(()=>{
				let question = this.form.Questions[index];
				if(type == 1){ /*多选*/
					this.showForm.MultiChoiceNum =  String(Number(this.showForm.MultiChoiceNum) - 1);
					this.showForm.MultiChoiceScore =  String(Number(this.showForm.MultiChoiceScore) - Number(question.RightScore));
					this.showForm.TotalScore =  String(Number(this.showForm.TotalScore) - Number(question.RightScore));
					this.form.Questions.splice(index, 1);
				}else if(type == 2){/*单选*/
					this.showForm.SingleChoiceNum =  String(Number(this.showForm.SingleChoiceNum) - 1);
					this.showForm.SingleChoiceScore =  String(Number(this.showForm.SingleChoiceScore) - Number(question.RightScore));
					this.showForm.TotalScore =  String(Number(this.showForm.TotalScore) -Number(question.RightScore));
					this.form.Questions.splice(index, 1);
				}else if(type == 3){
					this.showForm.AskAnswerNum =  String(Number(this.showForm.AskAnswerNum) - 1);
					this.form.Questions.splice(index, 1);
				}

            }).catch( ()=>{
                //
            })

        },

        addAnswerOne: function(index){      // 增加小题中的选项
            var one = this.form.Questions[index];
            if(one){
                one.Answers.push({});
            }

        },
        delAnswerOne: function(outerIndex, index){      // 删除小题中的选项
            var one = this.form.Questions[outerIndex];
            if(one){
                one.Answers = Array.prototype.slice.call(one.Answers, 0);
                one.Answers.splice(index, 1);
            }
        },
        saveAnswerOne: function(outerIndex, type){
            var status = this.judgeOkOne(outerIndex, type),
                    flag = status.flag;

            if(flag){
                this.form.Questions[outerIndex].editFlag = false;
                this.editFlag = false;
                this.cancelOneFlag = false;

                let question = this.form.Questions[outerIndex];
                if(type == 1){
					this.showForm.MultiChoiceNum =  String(Number(this.showForm.MultiChoiceNum) + 1);
					this.showForm.MultiChoiceScore =  String(Number(this.showForm.MultiChoiceScore) + Number(question.RightScore));
					this.showForm.TotalScore =  String(Number(this.showForm.TotalScore) + Number(question.RightScore));
                }else if(type == 2){
					this.showForm.SingleChoiceNum =  String(Number(this.showForm.SingleChoiceNum) + 1);
					this.showForm.SingleChoiceScore =  String(Number(this.showForm.SingleChoiceScore) + Number(question.RightScore));
					this.showForm.TotalScore =  String(Number(this.showForm.TotalScore) + Number(question.RightScore));
                }else if(type == 3){
					this.showForm.AskAnswerNum =  String(Number(this.showForm.AskAnswerNum) + 1);
                }
            }else{
                this.$message.error(status.msg);
            }
        },

		delEdit(outerIndex,type){

			let question = this.form.Questions[outerIndex];
			if(type == 1){
				this.showForm.MultiChoiceNum =  String(Number(this.showForm.MultiChoiceNum) - 1);
				this.showForm.MultiChoiceScore =  String(Number(this.showForm.MultiChoiceScore) - Number(question.RightScore));
				this.showForm.TotalScore =  String(Number(this.showForm.TotalScore) - Number(question.RightScore));
				this.form.Questions.splice(outerIndex, 1);
				this.editFlag = false;
			}else if(type == 2){
				this.showForm.SingleChoiceNum =  String(Number(this.showForm.SingleChoiceNum) - 1);
				this.showForm.SingleChoiceScore =  String(Number(this.showForm.SingleChoiceScore) - Number(question.RightScore));
				this.showForm.TotalScore =  String(Number(this.showForm.TotalScore) -Number(question.RightScore));
				this.form.Questions.splice(outerIndex, 1);
				this.editFlag = false;
			}else if(type == 3){
				this.showForm.AskAnswerNum =  String(Number(this.showForm.AskAnswerNum) - 1);
				this.form.Questions.splice(outerIndex, 1);
				this.editFlag = false;
			}

		},

        cancelAnswerOne: function(outerIndex){
            this.editFlag = false;
            this.form.Questions.splice(outerIndex, 1);
        },
        judgeOkOne: function(outerIndex, type){

            var one = this.form.Questions[outerIndex],
                    answers = one.Answers,
                    len = answers.length,
                    status = {flag: true, msg: ''};

            if(type == 3){
                if(!one.QuestionTitle) return {flag: false, msg: '请输入标题'};
            }else{
                if(!one.QuestionTitle) return {flag: false, msg: '请输入标题'};
                if(!one.RightScore) return {flag: false, msg: '请输入分数'};
                if(type==1){
                    if(one.RightAnswerIndexs.length==0){
						return {flag: false, msg: '请选择正确答案'};
                    }else if(one.RightAnswerIndexs.length== 1){
						return {flag: false, msg: '多选题至少选择两个正确答案'};
                    }
                }else if(type==2){
                    if(one.RightAnswerIndexs==='') {
                        return {flag: false, msg: '请选择正确答案'};
                    }
                }
                for(var i= 0; i<len; i++){
                    if(!answers[i].AnswerValue){
                        return {flag: false, msg: '请输入问题描述'};
                    }
                }
            }
            return status;
        },

        judgeCheckOn: function(index, arr){
			if(!arr){
				return false;
			};
            if(arr.indexOf(index) > -1){
                return true;
            }
            return false;
        },
        checkAnswerOne: function(index, arr, outIndex, limit){

            var arr = arr ? arr.split(',') : [];
            var pos = arr.indexOf((index).toString());
            if(pos>-1){
                arr.splice(pos, 1);
            }else{
                arr.push(index);
            }
            this.form.Questions[outIndex].RightAnswerIndexs = arr.join(',');
        },

        submitForm: function(formName){
            if(this.editFlag){
                this.$message.error(this.editTip);
                return ;
            };

            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.doAxios();
                } else {
                    return false;
                }
            });
        },
        doAxios(){

            var questions = this.form.Questions;
            questions = com.toArray(questions);
            questions.forEach( (one)=>{
                for(var iOne, i=0,len=one.Answers.length; i<len; i++){
                    iOne = one.Answers[i];
                    iOne.AnswerKey = answerArr[i];
                }
            } )
            questions = null;

			let TrainID = this.$route.query.TrainID;
			this.form["TrainID"] = TrainID;

			if(this.form.Questions.length == 0){
				this.$message.error('您还没有添加试题，请添加试题后再提交！');
			}else if(this.form.Questions.length > 0){
				axios.post('/com/exam/add', qs.stringify(
					this.form,
				)).then( (res)=>{
					var d = res.data;
					if(d.flag == 1){
						this.form.ExamID = parseInt(d.data.id);
						this.hasExamId = true;
						this.mainEditFlag = false;
						this.editFlag = false;
						this.initHasTest = true;
						this.$message.success('上传成功');
						this.submitFlag = true;
						location.assign('/training/exam?ExamID='+parseInt(d.data.id)+'&TrainID='+TrainID);
					}else{
						this.submitFlag = false;
						this.$message.error(d.msg);
					}
				} );
			}

        },

        getLibList: function(page){
//            this.libLoading = true;
			this.pageLibInfo.page = page || 1;
            axios.post('/com/exam/getLibList', qs.stringify({
                pagesize:this.pageLibInfo.pageSize,
                page:this.pageLibInfo.page,
                keywords: this.libKeyword
            })).then((res) => {
                var d = res.data;
                this.libLoading = false;
                if(d.flag == 1){
                    this.libList = d.data.Rows;
                    this.pageLibInfo.total=Number(d.data.Total);
                }else {
                    this.$message.error(d.msg)
                }
            })

        },
        getLibOne: function(id){
            axios.post('/com/exam/getLib', qs.stringify({
                examLibID: id
            })).then( (res)=>{
                var d = res.data;

                this.libListFlag = false;
                this.editFlag = false;

                if(d.flag == 1){
                    d = d.data;
                    d.AllowCostTime = +d.AllowCostTime;

                    d.Questions.forEach(function(one){
                        if(one.QuestionType==2){
                            one.RightAnswerIndexs = +one.RightAnswerIndexs;
                        }


                    });

					d.Questions.forEach(function(one){
						one.editFlag = false;
					})

                    //this.editFlag = true;
                    this.form = d;
					this.form.CateName = '';
					this.form.InfoCateID = '';

                    this.form.ExamLibID = id;
                    this.step = 1;

					this.showForm.SingleChoiceNum = d.SingleChoiceNum;
					this.showForm.MultiChoiceNum = d.MultiChoiceNum;
					this.showForm.AskAnswerNum = d.AskAnswerNum;
					this.showForm.SingleChoiceScore = d.SingleChoiceScore;
					this.showForm.MultiChoiceScore = d.MultiChoiceScore;
					this.showForm.TotalScore = d.TotalScore;


					let TrainID = this.$route.query.TrainID;
					this.form["TrainID"] = TrainID;
					axios.post('/com/train/applyLibExam', qs.stringify(
                        {
							trainID: TrainID,
							infoType: 1,
							examLibID:id
                        }
					)).then( (res)=>{
						var d = res.data;
						if(d.flag == 1){
//							this.form.ExamID = parseInt(d.data.ExamID);

							this.paperIsApply = true;

							this.hasExamId = true;
							this.mainEditFlag = false;
							this.editFlag = false;
							this.initHasTest = true;
							this.$message.success('应用成功');
							this.submitFlag = true;
							location.assign('/training/exam?ExamID='+parseInt(d.data.ExamID)+'&TrainID='+TrainID);
						}else{
							this.submitFlag = false;
							this.$message.error(d.msg);
						}
					} );

                }
            } );
        },
        getQuestionOne(id,one){
            axios.post('/com/exam/getQuestion', qs.stringify({
                QID: id,
				isApply: 1,
            })).then( (res)=>{
                var d = res.data;

                this.libListFlag = false;
                this.editFlag = false;

                if(d.flag == 1){
                    d = d.data;
                    this.questionListFlag = false;
                    if(d.QuestionType==2){
                        d.RightAnswerIndexs = +d.RightAnswerIndexs;
                    }
                    d.editFlag = false;
                    this.form.Questions.push(d);

                    if(one.QuestionType == 1){
						this.showForm.MultiChoiceNum = String(Number(this.showForm.MultiChoiceNum) + 1);
						this.showForm.MultiChoiceScore = String(Number(this.showForm.MultiChoiceScore) + Number(d.RightScore));
						this.showForm.TotalScore = String(Number(this.showForm.TotalScore) + Number(d.RightScore));
                    }else if(one.QuestionType == 2){
						this.showForm.SingleChoiceNum = String(Number(this.showForm.SingleChoiceNum) + 1);
						this.showForm.SingleChoiceScore = String(Number(this.showForm.SingleChoiceScore) + Number(d.RightScore));
						this.showForm.TotalScore = String(Number(this.showForm.TotalScore) + Number(d.RightScore));
                    }else if(one.QuestionType == 3){
						this.showForm.AskAnswerNum =  String(Number(this.showForm.AskAnswerNum) + 1);
                    }

                }else{
                	this.$message.error(d.msg);
                }
            } );
        },
        getQuestionList(page){
			this.pageQuestionInfo.page=page || 1 ;
//            this.questionLoading = true;
            axios.post('/com/exam/getLibQuestionList', qs.stringify({
                pagesize:this.pageQuestionInfo.pageSize,
                page: this.pageQuestionInfo.page,
                keywords: this.questionKeyword
            })).then((res) => {
                var d = res.data;
                this.questionLoading = false;
                if(d.flag == 1){
                    this.questionList = d.data.Rows;
                    this.pageQuestionInfo.total=Number(d.data.Total);
                }else {
                    this.$message.error(d.msg);
                }
            });

        },

		doSaveAllTitle(){
			if(!this.form.ExamTitle){
				this.$message.error('请输入考试名称');
			}else if(!this.form.ExamDesc){
				this.$message.error('请输入考试描述');
			}else if(!this.form.PassScore){
				this.$message.error('请输入合格分数');
			}else if(!this.form.AllowCostTime){
				this.$message.error('请输入考试时长');
			}else{
				axios.post('/com/exam/edit', qs.stringify({
					examID: this.form.ExamID,
					examTitle: this.form.ExamTitle,
					examDesc: this.form.ExamDesc,
					passScore:this.form.PassScore,
					allowCostTime:this.form.AllowCostTime
				})).then( (res) => {
					var d = res.data;
					if(d.flag == 1){
						this.$message.success('编辑成功');
						this.mainEditFlag = false;
					}else{
						this.$message.error(d.msg);
					}
				} );
			}
        },

		saveEditNewAnswerOne(item,outerIndex, type){
			let self =this;
			var status = this.judgeOkOne(outerIndex, type),
				flag = status.flag;
			if(flag){
				self.getAllTopicId();
				self.doSendNewTopic(item,outerIndex);
			}else{
				this.$message.error(status.msg);
			}
        },

		getAllTopicId(){
            let self = this;
            if(self.existExamID){
				let oldArr = [];
				self.form.Questions.forEach((one)=>{
					oldArr.push(Number(one.ExamQID));
				});
				let arr = oldArr;
				let str= arr.join(",");
				self.ExamQIDs = str;
            }else{
            	this.$message.error('还没有试卷！快来应用一张试卷吧');
            }
		},

		doSendNewTopic(item,outerIndex){
			let self =this;
			if(item.QuestionType == 2){

				axios.post('/com/exam/edit', qs.stringify({
					examID: self.form.ExamID,
					examQIDs: self.ExamQIDs,
					question: {
						QuestionType: item.QuestionType,
						QuestionTitle: item.QuestionTitle,
						RightAnswerIndexs: item.RightAnswerIndexs,
						RightScore: item.RightScore,
						Answers:  item.Answers,
					},
				})).then( (res) => {
					var d = res.data;
					if(d.flag == 1){
						self.getAllSaveEditOne(outerIndex);
						self.$message.success('编辑成功');

						self.form.Questions[outerIndex].editFlag = false;
						self.editFlag = false;
						self.cancelOneFlag = false;

						self.editOldTopic = false; // 未修改
						self.createNewTopic = false; // 未新增

					}else{
						self.$message.error(d.msg);
					}
				} );

			}else if(item.QuestionType == 1){
				axios.post('/com/exam/edit', qs.stringify({
					examID: self.form.ExamID,
					examQIDs: self.ExamQIDs,
					question: {
						QuestionType: item.QuestionType,
						QuestionTitle: item.QuestionTitle,
						RightAnswerIndexs: item.RightAnswerIndexs,
						RightScore: item.RightScore,
						Answers:  item.Answers,
					},
				})).then( (res) => {
					var d = res.data;
					if(d.flag == 1){
						self.getAllSaveEditOne(outerIndex);
						self.$message.success('编辑成功');

						self.form.Questions[outerIndex].editFlag = false;
						self.editFlag = false;
						self.cancelOneFlag = false;
						self.editOldTopic = false; // 未修改
						self.createNewTopic = false; // 未新增

					}else{
						self.$message.error(d.msg);
					}
				} );

			}else if(item.QuestionType == 3){
				axios.post('/com/exam/edit', qs.stringify({
					examID: self.form.ExamID,
					examQIDs: self.ExamQIDs,
					question: {
						QuestionType: item.QuestionType,
						QuestionTitle: item.QuestionTitle,
						RightScore: item.RightScore,
					},
				})).then( (res) => {
					var d = res.data;
					if(d.flag == 1){
						self.getAllSaveEditOne(outerIndex);
						self.$message.success('编辑成功');

						self.form.Questions[outerIndex].editFlag = false;
						self.editFlag = false;
						self.cancelOneFlag = false;
						self.editOldTopic = false; // 未修改
						self.createNewTopic = false; // 未新增

					}else{
						self.$message.error(d.msg);
					}
				} );
			}
        },

		cancelEditNewAnswerOne(outerIndex){
            let self = this;
			self.editFlag = false;
			self.form.Questions.splice(outerIndex, 1);
        },

		saveEditOldAnswerOne(item,outerIndex, type){
			let self =this;
			var status = this.judgeOkOne(outerIndex, type),
				flag = status.flag;

			if(flag){
				self.getAllTopicId();
				self.doSendOldTopic(item,outerIndex);
			}else{
				this.$message.error(status.msg);
			}
        },

        getAllSaveEditOne(){
			let self =this;
			let ExamID = this.$route.query.ExamID;
			axios.post('/com/exam/get', qs.stringify({
				examID: ExamID
			})).then( (res)=>{
				var d = res.data;
				if(d.flag == 1){
					this.form.SingleChoiceNum = d.data.SingleChoiceNum;
					this.form.MultiChoiceNum = d.data.MultiChoiceNum;
					this.form.AskAnswerNum = d.data.AskAnswerNum;
					this.form.SingleChoiceScore = d.data.SingleChoiceScore;
					this.form.MultiChoiceScore = d.data.MultiChoiceScore;
					this.form.TotalScore = d.data.TotalScore;
                    self.form.Questions = d.data.Questions;
					self.form.Questions.forEach((item)=>{
						self.contentList = item.Answers;
                        if(item.QuestionType==2){
                            item.RightAnswerIndexs = +item.RightAnswerIndexs;
                        }
					});
					self.lastIndex = (this.contentList.length - 1);
				}else{
					this.$message.error(d.msg);
				}
			} );
        },

		doSendOldTopic(item,outerIndex){
			let self =this;
			if(item.QuestionType == 2){

				axios.post('/com/exam/edit', qs.stringify({
					examID: self.form.ExamID,

					examQIDs: self.ExamQIDs,
					question: {
						ExamQID: item.ExamQID,
						QuestionType: item.QuestionType,
						QuestionTitle: item.QuestionTitle,
						RightAnswerIndexs: item.RightAnswerIndexs,
						RightScore: item.RightScore,
						Answers:  item.Answers,
					},
				})).then( (res) => {
					var d = res.data;
					if(d.flag == 1){
						self.getAllSaveEditOne(outerIndex);
						self.$message.success('编辑成功');

						self.form.Questions[outerIndex].editFlag = false;
						self.editFlag = false;
						self.cancelOneFlag = false;

						self.editOldTopic = false;
						self.createNewTopic = false;

					}else{
						self.$message.error(d.msg);
					}
				} );

			}else if(item.QuestionType == 1){
				axios.post('/com/exam/edit', qs.stringify({
					examID: self.form.ExamID,

					examQIDs: self.ExamQIDs,
					question: {
						ExamQID: item.ExamQID,
						QuestionType: item.QuestionType,
						QuestionTitle: item.QuestionTitle,
						RightAnswerIndexs: item.RightAnswerIndexs,
						RightScore: item.RightScore,
						Answers:  item.Answers,
					},
				})).then( (res) => {
					var d = res.data;
					if(d.flag == 1){
						self.getAllSaveEditOne(outerIndex);
						self.$message.success('编辑成功');

						self.form.Questions[outerIndex].editFlag = false;
						self.editFlag = false;
						self.cancelOneFlag = false;
						self.editOldTopic = false;
						self.createNewTopic = false;

					}else{
						self.$message.error(d.msg);
					}
				} );

			}else if(item.QuestionType == 3){
				axios.post('/com/exam/edit', qs.stringify({
					examID: self.form.ExamID,

					examQIDs: self.ExamQIDs,
					question: {
						ExamQID: item.ExamQID,
						QuestionType: item.QuestionType,
						QuestionTitle: item.QuestionTitle,
						RightScore: item.RightScore,
					},
				})).then( (res) => {
					var d = res.data;
					if(d.flag == 1){
						self.getAllSaveEditOne(outerIndex);
						self.$message.success('编辑成功');

						self.form.Questions[outerIndex].editFlag = false;
						self.editFlag = false;
						self.cancelOneFlag = false;

						self.editOldTopic = false;
						self.createNewTopic = false;

					}else{
						self.$message.error(d.msg);
					}
				} );
			}


		},

		holdOldOne(index){
			let ExamID = this.$route.query.ExamID;
			axios.post('/com/exam/get', qs.stringify({
				examID:ExamID
            })).then( (res) => {
                var d = res.data;
                if(d.flag == 1){
					this.form.Questions[index].QuestionTitle =  d.data.Questions[index].QuestionTitle;
					this.form.Questions[index].QuestionType =  d.data.Questions[index].QuestionType;
					this.form.Questions[index].RightAnswerIndexs =  d.data.Questions[index].RightAnswerIndexs;
					this.form.Questions[index].QuestionTitle =  d.data.Questions[index].QuestionTitle;
					this.form.Questions[index].ExamQID =  d.data.Questions[index].ExamQID;
					this.form.Questions[index].RightScore =  d.data.Questions[index].RightScore;
					this.form.Questions[index].Answers =  d.data.Questions[index].Answers;
					this.editFlag = false;
					this.form.Questions[index].editFlag = false;
                }else{
                	this.$message.error(d.msg);
                }
            } );
		},

		delEditOne(index,outer){
			let self =this;

			self.getAllDelID(index,outer);
			axios.post('/com/exam/edit', qs.stringify({
				examID: self.form.ExamID,
				examQIDs: self.examQIDs,
				delQID: outer.ExamQID,
			})).then( (res) => {
				var d = res.data;
				if(d.flag == 1){
//                    self.getOne(ExamID);
//					SingleChoiceNum: '0',
//						MultiChoiceNum: '0',
//						AskAnswerNum: '0',
//						SingleChoiceScore: '0',
//						MultiChoiceScore: '0',
//						AskAnswerScore: '0',
//						TotalScore: '0'
					self.getEditTotalNum(index);

				}else{
					self.$message.error(d.msg);
				}
			} );
        },

        getEditTotalNum(index){
			let self =this;
			let ExamID = this.$route.query.ExamID;
			axios.post('/com/exam/get', qs.stringify({
				examID: ExamID
			})).then( (res)=>{
				var d = res.data;
				if(d.flag == 1){
					this.form.SingleChoiceNum = d.data.SingleChoiceNum;
					this.form.MultiChoiceNum = d.data.MultiChoiceNum;
					this.form.AskAnswerNum = d.data.AskAnswerNum;
					this.form.SingleChoiceScore = d.data.SingleChoiceScore;
					this.form.MultiChoiceScore = d.data.MultiChoiceScore;
					this.form.TotalScore = d.data.TotalScore;

					self.$message.success('删除成功');
					self.form.Questions.splice(index, 1);
					self.form.Questions.forEach((item)=>{
						self.contentList = item.Answers;
					});
					self.lastIndex = (this.contentList.length - 1);
				}else{
					this.$message.error(d.msg);
				}
			} );
        },

		getAllDelID(index,outer){
			let self = this;
			let oldArr = [];
			self.form.Questions.forEach((one)=>{
				oldArr.push(Number(one.ExamQID));
			});
			let arr = oldArr;
			arr.splice(index,1);
			let str= arr.join(",");
			self.examQIDs = str;
		},

		delEditTwo(index,outer){
            let self =this;
			self.getAllDelID(index,outer);
			axios.post('/com/exam/edit', qs.stringify({
				examID: self.form.ExamID,
				examQIDs: self.examQIDs,
				delQID: outer.ExamQID,
			})).then( (res) => {

				var d = res.data;
				if(d.flag == 1){
					self.getEditTotalNum(index);
				}else{
					self.$message.error(d.msg);
				}
			} );
        },
		delEditThree(outerIndex){
			this.$confirm('确认删除？').then(()=>{
				this.editFlag = false;
				this.form.Questions.splice(outerIndex, 1);
			}).catch( ()=>{
				//
			})
        },

		switchUp(one,index,list,outer){
			let self = this;

			if(outer.QuestionType == 2){
				let arr = Number(outer.RightAnswerIndexs);
				if(arr == index){
					arr = arr-1;
					outer.RightAnswerIndexs = arr;
					pubSwitchUp(one,index,list,outer);
				}else{
					if(arr == (index-1)){
						arr = arr +1;
						outer.RightAnswerIndexs = arr;
						pubSwitchUp(one,index,list,outer);
					}else{
						pubSwitchUp(one,index,list,outer);
					}
				}
			}else if(outer.QuestionType == 1){
				let arr = outer.RightAnswerIndexs.split(',');
				if(arr.indexOf(String(index))> -1){
					if(arr.indexOf(String(index-1)) > -1){
						pubSwitchUp(one,index,list,outer);
					}else{
						arr[arr.indexOf(String(index))] = String(Number(arr[arr.indexOf(String(index))]) -1);
						outer.RightAnswerIndexs = arr.join(',');
						pubSwitchUp(one,index,list,outer);
					}
				}else{
					if(arr.indexOf(String(index-1)) > -1){
						arr[arr.indexOf(String(index-1))] = String(Number(arr[arr.indexOf(String(index-1))]) +1);
						outer.RightAnswerIndexs = arr.join(',');
						pubSwitchUp(one,index,list,outer);
					}else{
						pubSwitchUp(one,index,list,outer);
					}
				}
			}


			function pubSwitchUp(one,index,list,outer) {
				self.contentList = list;
				self.contentList.splice(index,1);
				self.contentList.splice(index-1,0,one);
				let itemNewLast = self.contentList[index-1].AnswerValue;
				let itemNewNext = self.contentList[index].AnswerValue;
				one.AnswerValue = itemNewLast;
				self.contentList[index].AnswerValue = itemNewNext;
			}
        },

		switchDown(one,index,list,outer){
			let self = this;
			if(outer.QuestionType == 2){
				let arr = Number(outer.RightAnswerIndexs);
				if(arr == index){
					arr = arr+1;
					outer.RightAnswerIndexs = arr;
					pubSwitchDown();
				}else{
					if(arr == (index+1)){
						arr = arr -1;
						outer.RightAnswerIndexs = arr;
						pubSwitchDown();
					}else{
						pubSwitchDown();
					}
				}

			}else if(outer.QuestionType == 1){
				let arr = outer.RightAnswerIndexs.split(',');
				if(arr.indexOf(String(index))> -1){
					if(arr.indexOf(String(index+1)) > -1){

						pubSwitchDown();

					}else{
						arr[arr.indexOf(String(index))] = String(Number(arr[arr.indexOf(String(index))]) +1);
						outer.RightAnswerIndexs = arr.join(',');

						pubSwitchDown();
					}
				}else{
					if(arr.indexOf(String(index+1)) > -1){
						arr[arr.indexOf(String(index+1))] = String(Number(arr[arr.indexOf(String(index+1))]) -1);
						outer.RightAnswerIndexs = arr.join(',');
						pubSwitchDown();
					}else{
						pubSwitchDown();
					}
				}
			}

			function pubSwitchDown(){
				self.contentList = list;
				self.contentList.splice(index,1);
				self.contentList.splice(index+1,0,one);
				let itemNewLast = self.contentList[index].AnswerValue;
				let itemNewNext = self.contentList[index+1].AnswerValue;
				one.AnswerValue = itemNewNext;
				self.contentList[index].AnswerValue = itemNewLast;
			}
		},
        initInfoCate(addFlag){
			axios.post('/com/info-cates/list').then( (res)=>{
				var d = res.data;
				if(d.flag == 1){
					this.InfoCateList = d.data.InfoCateList;

				}
			} );
        },

		monitorUrl(){
			if(this.submitFlag == false){

				pushHistory();
				window.addEventListener("popstate", function(e) {
					localStorage.removeItem('formInfo');
					window.location.assign('/training/training-manage');
				}, false);

				function pushHistory() {
					var state = {
						title: "title",
						url: ""
					};
					window.history.pushState(state, "title", "");
				}
			}
		},



	},
    mounted: function(){
        this.initPageEvent();
        this.getTrainName();
        this.getQuestionList();
        this.getLibList();
        this.initInfoCate();
        this.monitorUrl();
    }
}


</script>
